﻿//创建时间: 2011-04-08
//创建作者: 李城
//功能说明: CMS系统 用户登录验证 
using System;
using System.Collections.Generic;
using System.Text;
using TRPOP.Common;
using TRPOP.CMS.Model;
using System.Data;
using TRPOP.CMS.Business;
using TRPOP.CMS.Plugin;
using System.Web;
using Discuz.Toolkit;
namespace TRPOP.CMS.UserManage
{
    public class DiscuszAdminManage : IAdminUser
    {
        /// <summary>
        /// Session 标识
        /// </summary>
        const string mstrAdministratorship = "Administratorship";
        /// <summary>
        /// 缓存Key 所有的权限码
        /// </summary>
        const string mstrAllPermissionCahceKey = "AllPermissionCahceKey";

        const string mstrApi = "e4a1bb5769bb4ea662d15ad382257794";
        const string mstrSecret = "a06b83ec5baeb70b989764115a25adce";
        const string mstrUrl = @"http://qa.bbs.yorknet.cn/";
        const string mstrLoginout = @"http://qa.bbs.yorknet.cn/logout.aspx?userkey=dc3949ba";
        const string mstrRedirectLogin = @"http://qa.bbs.yorknet.cn/login.aspx?referer=http://qa.demo.cms.yorknet.cn/cms/";

        public bool AdminLogin(string strUserName, string strPassword)
        {
            return false;
        }

        public bool CheckLogin()
        {
            if (GetCurrentInfo() == null)
            {
                HttpContext.Current.Response.Redirect(mstrRedirectLogin);
                return false;
            }
            return true;
        }

        public object getUserBaseInfo()
        {
            return GetCurrentInfo();
        }

        public string GetAdminNameById(int intUserID)
        {
            DiscuzSession ds = new DiscuzSession(mstrApi, mstrSecret, mstrUrl);
            User user = ds.GetUserInfo((long)intUserID);
            if (user == null)
                return null;
            return user.UserName;
        }

        public object getUserBaseInfo(int intid)
        {
            DiscuzSession ds = new DiscuzSession(mstrApi, mstrSecret, mstrUrl);
            User user = ds.GetUserInfo((long)intid);
            if (user == null)
                return null;
            AdminUserInfo oUserInfo = new AdminUserInfo();
            oUserInfo.LogName = user.UserName;
            oUserInfo.Name = user.UserName;
            oUserInfo.UserBaseId = (int)user.Adminid;
            return oUserInfo;
        }

        public bool CheckUserPermission(PermissionKeys.PermissionEnum oPermissionKeys)
        {
            return true;
        }

        public bool CheckUserPermission(string strPermissionKeywords)
        {
            return true;
        }

        public void LoginOut()
        {
            HttpContext.Current.Response.Redirect(mstrLoginout);
            return;
        }

        public List<object> GetPermissionListByParentId(int intParentid)
        {
            return new List<object>();
        }

        public string GetEnabledNodeIds()
        {
            return "all";
        }

        public bool SaveUserInfo(object obj)
        {
            return true;
        }

        public bool DeleteUserInfoById(int intUserID)
        {
            return true;
        }

        public List<object> GetListByConditionForRealPubCount(int topn, string condition, string orderby)
        {
            return new List<object>();
        }

        public List<object> GetUserListByCondition(int topn, string condition, string orderby)
        {
            return new List<object>();
        }

        public bool AddPermissionByNodeId(int intNodeId)
        {
            return true;
        }

        #region
        public static HttpCookie GetCurrentCookie()
        {
            HttpContext ocContext = HttpContext.Current;
            HttpCookie ohcCookie = ocContext.Request.Cookies[@"dnt"];
            return ohcCookie;
        }
        public static AdminUserInfo GetCurrentInfo()
        {
            HttpCookie oHttpCookie = GetCurrentCookie();
            if (oHttpCookie == null)
                return null;
            int intId = int.Parse(oHttpCookie.Values["userid"].ToString());
            DiscuzSession ds = new DiscuzSession(mstrApi, mstrSecret, mstrUrl);
            User user = ds.GetUserInfo((long)intId);
            if (user == null)
                return null;
            AdminUserInfo oUserInfo = new AdminUserInfo();
            oUserInfo.LogName = user.UserName;
            oUserInfo.Name = user.UserName;
            oUserInfo.UserBaseId = (int)user.Adminid;
            return oUserInfo;
        }
        #endregion


    }
}
